<?
require_once(dirname(dirname(dirname(__FILE__))) . "/_includes/config.php");
require_once(dirname(dirname(dirname(__FILE__))) . "/_includes/classes/paginacao.class.php");

if ($_REQUEST['form_enviado'] == 1){ 
	$nm_categoria = $_REQUEST['nm_categoria'];
	$cd_categoria_pai = $_REQUEST['cd_categoria_pai'];	
	if ($cd_categoria_pai){
		$sql_where = " AND a.cd_categoria_pai = '$cd_categoria_pai' "; 		
	}
}
?>

<h2>1 | Selecione a Subcategoria</h2>
<form name="form1" method="post" action="">
  <div class="formArea">
    
<table border="0" cellpadding="0" cellspacing="0" class="formCampos">
  <tr> 
    <td class="formLabel">Subcategoria:</td>
    <td> 
		<input name="nm_categoria" type="text" class="formInput formGrande" id="nm_categoria" value="<?=$nm_categoria?>">
  	</td>
  </tr>
      <tr>
        <td class="formLabel">Categoria:</td>
        <td><?=print_select("categoria", "cd_categoria", "nm_categoria", "cd_categoria_pai", $cd_categoria_pai, 1, "where cd_categoria_pai is null order by nm_categoria")?></td>
      </tr>
  <tr>
    <td class="formLabel">&nbsp;</td>
    <td>
		<input name="formButtonOk" type="submit" class="formButton" id="formButtonOk" value="OK"> 
		<input name="form_enviado" type="hidden" id="form_enviado" value="1">
	</td>
  </tr>
</table>
</form>
<?
$sql = "SELECT a.cd_categoria, a.ic_ordem_categoria, a.nm_categoria as subcat, b.nm_categoria as cat FROM categoria a, categoria b WHERE a.nm_categoria LIKE '%$nm_categoria%' ". $sql_where ." AND a.cd_categoria_pai is not null and a.cd_categoria_pai = b.cd_categoria order by a.nm_categoria,b.nm_categoria";
$pg = new paginacao($sql);
$pg->consulta;

$pg->cabecalho = '
  <tr class="linhaHeader">
    <td width="50">Ordem</td>
    <td width="250">Subcategoria</td>
    <td>Categoria</td>
  </tr>
  ';

$pg->linha = '
  <tr class="linha<?=$c&1?>" onMouseOver="this.className=\'linhaOver\'; this.style.cursor=\'pointer\'" onMouseOut="this.className=\'linha<?=$c++&1?>\'" onClick="window.location.href=\'?cd_categoria=<?=$lst[\'cd_categoria\']. "&" . $_SERVER[\'QUERY_STRING\']?>\'">
    <td><?=$lst[\'ic_ordem_categoria\']?></td>
	<td><?=$lst[\'subcat\']?></td>	
	<td><?=$lst[\'cat\']?></td>
  </tr>
  ';

$pg->resultado(); 
	
?>